package com.lesama.test;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Server {
    public static void main(String[] args) throws IOException {
        // 1. 创建server对象
        ServerSocket server = new ServerSocket(8888);

        // 2. 获取客户端连接
        System.out.println("服务器开始接收请求");

        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                2,
                5,
                60,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(10),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );

        while(true) {
            Socket socket = server.accept();
            pool.submit(new SubmitFileTask(socket));
        }
    }
}